package com.wechat.message.action;


import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.core.action.BaseAction;
import com.util.message.TemplateMessage;
import com.wechat.admin.model.Address;
import com.wechat.admin.model.Order;
import com.wechat.admin.model.User;

@Controller
public class AddOrderAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	
	@RequestMapping(value="/mypostion")
	public String MyPostion(ModelMap map) {
		//从数据库中查询用户的地址
		return JSP+"mypostion";
	}
	
	@RequestMapping(value="/add_position")
	public String AddPostion() {
		return JSP+"add_position";
	}

	@RequestMapping(value="/posSave")
	public String positionSave(Address addr, ModelMap map) {
		//用户的地址保存到数据库
		map.addAttribute("nametext", addr.getName());
		map.addAttribute("phonetext", addr.getPhone());
		map.addAttribute("addresstext", addr.getAddr());
		//System.out.println(addr);
		return JSP + "mypostion";
	}
	
	@RequestMapping(value="/company_list")
	public String CompanyList() {
		//从数据库中查询用户的地址
		return JSP+"company_list";
	}
	
	@RequestMapping(value="/number")
	public String Number(String company, ModelMap map) {
		map.addAttribute("company", company);
		return JSP+"number";
	}
	
	@RequestMapping(value="/myinfo")
	public String myInfo() {
		return JSP+"myinfo";
	}

	@RequestMapping(value="/saveOrder")
	public String saveOrder(Address addr, Order order, String notes) throws Exception {
		User user = (User)getRequest().getSession().getAttribute("user");
		if(!StringUtils.isEmpty(user.getOpenid()) && !StringUtils.isEmpty(addr.getPhone()) && !StringUtils.isEmpty(order.getNumber())){
			TemplateMessage.sendTemplateMsg(user.getOpenid(), user.getAddr(), user.getOrder(), notes);
			user.setAddr(new Address());
			user.setOrder(new Order());
		}
		getRequest().getSession().setAttribute("user", user);
		return JSP + "paijian";
	}
	
	@RequestMapping(value="/dingdan")
	public String dingDan(){
		return JSP + "dingdan";
	}

	@RequestMapping(value="/update_addr")
	public String updateAddr(){
		return JSP + "update_addr";
	}

}
